<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function getData(url) {
            var p = new Promise((reslove, reject) => {
                let xhr = new XMLHttpRequest()

                xhr.open('get', url)

                xhr.send()

                xhr.onreadystatechange = function() {
                    if (xhr.readyState !== 4) return
                    if (xhr.readyState === 4 && xhr.status === 200) {
                        reslove(xhr.responseText)
                    } else {
                        reject('服务器错误')
                    }
                }
            })
            return p
        }
        getData('http://localhost:3000/data')
            .then((data) => {
                console.log(data)
                return getData('http://localhost:3000/data1')
            }).then((data) => {
                console.log(data)
                return getData('http://localhost:3000/data2')
            }).then((data) => {
                console.log(data)
            })
    </script>
</body>

</html>